package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.RbacRoleDao;
import com.woniuxy.entity.RbacRole;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.RoleMenuDTO;
import com.woniuxy.service.RbacRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RbacRoleServiceImpl implements RbacRoleService {
    @Autowired(required = false)
    RbacRoleDao rbacRoleDao;


    @Override
    public ResponseEntity findAll(int currentPage, int pageSize, RbacRole rbacRole) {
        PageHelper.startPage(currentPage,pageSize);
        List<RbacRole> rbacRoleList = rbacRoleDao.findAll();
        PageInfo page = new PageInfo(rbacRoleList);
        return new ResponseEntity<PageInfo>(200,"角色查询成功！",page);
    }

    @Override
    public ResponseEntity saveMenu(RoleMenuDTO roleMenuDTO) {
        //这种中间表的操作，普遍都不会使用更新方法
        //常规操作都是先删除再插入新的数据
        int i = rbacRoleDao.deleteById(roleMenuDTO.getRoleId());
        //数据插入进去
        rbacRoleDao.saveMenu(roleMenuDTO);
        return null;

    }
}
